<?php
/**
 * 巡查记录功能相关接口
 * @authors Hex (hex@zpdchina.com)
 * @date    2017-03-09 17:25:32
 * @version $Id$
 */

class XunchajiluController extends Yaf_Controller_Abstract {

    //获取巡查记录数据--用于Android端的service同步数据
    public function getXunchaDataJsonAction()
    {
        //获取参数
        $request = $this->getRequest();
        $yiyuan_id = $request->getPost('yiyuan_id',0);
        $user_department = $request->getPost('user_department','');
        $modify_time = $request->getPost('modify_time','');
        $json_data_str = $request->getPost('data','');
        $compression_http_data = $request->getPost('compression_http_data','off');

//        if(empty($yiyuan_id))
//            Utility::apiJsonError(30001, '医院编号不能为空');
        if(empty($user_department))
            Utility::apiJsonError(30010, '科室不能为空');
//        if(empty($json_data_str))
//            Utility::apiJsonError(30011, '上传数据不能为空');
        // 解压缩数据
        $json_data = json_decode(Utility::uncompress($json_data_str, $compression_http_data));
        $xuncha_mdl = new XunchajiluDataModel;
        $field_arr = $xuncha_mdl->_field_arr;
        $xuncha_data = $xuncha_mdl->getXunchaData($user_department,$json_data,$modify_time);
        $async_result = Utility::formatToSqlStrExtends($xuncha_data, 'zhuyuan_xuncha_jilu_lishi', 'update_sql', $field_arr);
        $result["response_state"] = "true";
        $result["response_info"] = "数据同步成功:)";
        if(empty($async_result)){
            $result["update_sql"] = array();
        }else{
            $result["update_sql"] = $async_result;
        }
        $result['msg'] = "";
        $result['error'] = 200;
        Utility::apiJsonResultExtends($result);
    }


    //获取巡查记录明细
    public function getXunchaDetailDataJsonAction()
    {
        //获取参数
        $request = $this->getRequest();
        $yiyuan_id = $request->getPost('yiyuan_id',0);
        $user_department = $request->getPost('user_department','');
        $modify_time = $request->getPost('modify_time','');
        $json_data_str = $request->getPost('data','');
        $compression_http_data = $request->getPost('compression_http_data','off');

//        if(empty($yiyuan_id))
//            Utility::apiJsonError(30001, '医院编号不能为空');
        if(empty($user_department))
            Utility::apiJsonError(30010, '科室不能为空');
//        if(empty($json_data_str))
//            Utility::apiJsonError(30011, '上传数据不能为空');
        // 解压缩数据
        $json_data = json_decode(Utility::uncompress($json_data_str, $compression_http_data));

        $xuncha_mdl = new XunchajiluDataModel();

        $field_arr = $xuncha_mdl->_field_detail_arr;
        $xuncha_detail_data = $xuncha_mdl->getXunchaDetailData($user_department,$json_data,$modify_time);
        $async_result = Utility::formatToSqlStrExtends($xuncha_detail_data, 'zhuyuan_xuncha_jilu_detail_lishi', 'update_sql', $field_arr);
        $result["response_state"] = "true";
        $result["response_info"] = "数据同步成功:)";
        if(empty($async_result)){
            $result["update_sql"] = array();
        }else{
            $result["update_sql"] = $async_result;
        }
        $result['msg'] = "";
        $result['error'] = 200;
        Utility::apiJsonResultExtends($result);
    }

}